<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">学号/工号:</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="sno" placeholder="请填写学号/工号" class="layui-input" lay-verify="number" required />
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">姓名:</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="name" placeholder="请填写姓名" value="" class="layui-input"  required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">上传类型:</label>
                                        <div class="layui-input-block">
                                            <select lay-verify="required" name="type">
                                                <option value="PDF" selected>PDF</option>
                                                <option value="WORD">WORD</option>
                                                <option value="EXCEL">EXCEL</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">选择材料:</label>
                                        <div class="layui-input-block">
                                            <select lay-verify="required" name="stuff">
                                                <option value="勤工助学表" selected>勤工助学表</option>
                                                <option value="励志奖学金">励志奖学金</option>
                                                <option value="三好学生">三好学生</option>
                                                <option value="佣金">佣金</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注说明:</label>
                                        <div class="layui-input-block">
                                            <textarea placeholder="备注说明" name="remark" value="" class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;"
                                action=baseUrl+"/file/upload" method="post" enctype="multipart/form-data">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">学号/工号:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="sno" value="2222"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">姓名:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="name"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件类型:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id=type></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">材料名称:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="stuff"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">选择文件:</label>
                                        <input  type="file" name="file" id="file">
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注说明:</label>
                                        <div class="layui-input-block">
                                            <div class="layui-form-mid layui-word-aux" id="remark"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;确认信息&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        提交成功
                                    </div>
                                    <!--<div style="font-size: 14px;color: #666;margin-top: 20px;">提交成功</div>-->
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">返回首页</button>
                                    <button class="layui-btn layui-btn-primary">查看详情</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../api/baseApi.js" charset="utf-8"></script>
<script>

    layui.use([ 'form', 'step'], function () {
        // 定义后端地址

        var fromData;
        var file;
        var $ = layui.$,
            form = layui.form,
            step = layui.step
        // console.log(layui.setter.baseU,'setter')
        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '提交材料信息'
            }, {
                title: '确认信息'
            }, {
                title: '完成'
            }]
        });


        form.on('submit(formStep)', function (data) {
            $("#sno").html(data.field.sno)
            $("#name").html(data.field.name)
            $("#stuff").html(data.field.stuff)
            $("#type").html(data.field.type)
            $("#remark").html(data.field.remark)
            step.next('#stepForm');
            fromData = data.field;
            return false;
        });

        form.on('submit(formStep2)', function (data) {

            // 前

            console.log($("#file")[0])
            // let btn = document.getElementById("btn");
            // btn.onclick = function () {
                console.log(fromData.sno)
                var formdata = new FormData();
                formdata.append("sno",fromData.sno)
                formdata.append("name",fromData.name)
                formdata.append("type",fromData.type)
                formdata.append("stuff",fromData.stuff)
                formdata.append("remark",fromData.remark)
                formdata.append("file",$("#file")[0].files[0])
                $.ajax({
                    type:"post",
                    url:baseUrl+"/file/upload",
                    data:formdata,
                    processData: false,   // jQuery不要去处理发送的数据
                    contentType: false,   // jQuery不要去设置Content-Type请求头
                    dataType:'json'
                })
            // }
            // 后

            step.next('#stepForm');
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });
    })

</script>
</body>
</html>